package com.mbc.web.common.server;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.mbc.common.dao.DBManagerFactory;
import com.mbc.common.manager.UserMgr;

public class SessionListener implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent arg0) {
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent arg0) {
		UserMgr l_userMgr = new UserMgr(arg0.getSession().getId());
		try {
			l_userMgr.updateUserOnlineStatus(Long.parseLong(arg0.getSession().getAttribute(SessionConstants.USER_ID).toString()), false);
		} catch (Exception e) {
			e.printStackTrace();
		}
		DBManagerFactory.deleteProperties(arg0.getSession().getId());
		DBManagerFactory.deleteDataSource(arg0.getSession().getId());
	}

}
